# coding: utf-8
from sqlalchemy import Column, Integer, String, TIMESTAMP, Table, text
from sqlalchemy.sql.sqltypes import NullType
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()


def to_dict(self):
    return {c.name: getattr(self, c.name, None)
            for c in self.__table__.columns}


Base.to_dict = to_dict
metadata = Base.metadata


t_sqlite_sequence = Table(
    'sqlite_sequence', metadata,
    Column('name', NullType),
    Column('seq', NullType)
)


class UserAccount(Base):
    __tablename__ = 'user_account'

    id = Column(Integer, primary_key=True)
    account = Column(String, nullable=False)
    state = Column(Integer, server_default=text("1"))
    name = Column(String)
    created_at = Column(TIMESTAMP, server_default=text("datetime(CURRENT_TIMESTAMP,'localtime')"))
